import React from 'react'
import IndexPage from '../view/index/index'
import AboutPage from '../view/about/index'
import GetstartPage from '../view/getstart/index'
import UnknowPage from '../view/404/index'
import TopicPage from '../view/topic/index'
import UserPage from '../view/user/index'
import QueryString from 'qs'
const types = ['all', 'good', 'share', 'ask', 'job']

const route = [
    {
        path: '/',
        exact: true,
        render(props) {
            // console.log(props);
            let { location } = props
            let { search } = location
            let { tab, page } = QueryString.parse(search.substr(1))
            if ((tab === undefined && page === undefined )||( types.includes(tab) && (page === undefined || page > 0))) {
                return <IndexPage {...props} />
            }
            return < UnknowPage {...props} />
        }
    },
    {
        path: '/topic/:id',
        exact: true,
        render(props) {
            return <TopicPage {...props} />
        }
    },
    {
        path: '/user/:username',
        exact: true,
        render(props) {
            return <UserPage {...props} />
        }
    },
    {
        path: '/getstart',
        exact: true,
        render(props) {
            return <GetstartPage {...props} />
        }
    }, {
        path: '/about',
        exact: true,
        render(props) {
            return <AboutPage {...props} />
        }
    },
    {
        path: '',
        exact: true,
        render(props) {
            return <UnknowPage {...props} />
        }
    },
]

const nav = [
    {
        to: '/',
        text: '首页'
    },
    {
        to: '/getstart',
        text: '新手入门'
    },
    {
        to: '/about',
        text: '关于我们'
    },
]

const indexNavs = [
    {
        path: "/?tab=all",
        title: "全部"
    }, {
        path: "/?tab=good",
        title: "精华"
    }, {
        path: "/?tab=share",
        title: "分享"
    }, {
        path: "/?tab=ask",
        title: "问答"
    }, {
        path: "/?tab=job",
        title: "招聘"
    }
];


export { route, nav, indexNavs, types }